﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace Spotted.Core
{
    public class SpottedAppService : IAppService
    {
        private readonly PhoneApplicationFrame _rootFrame;
        private ProgressIndicator _progressIndicator;

        public SpottedAppService(PhoneApplicationFrame phoneApplicationFrame)
        {
            _rootFrame = phoneApplicationFrame;
        }

        #region Implementation of IAppService

        public PhoneApplicationFrame RootFrame
        {
            get { return _rootFrame; }
        }

        /// <summary>
        /// Shows the Progress Indicator associated with the SystemTray
        /// </summary>
        /// <param name="message">Optional message which can be displayed with the indicator</param>
        public void ShowProgressIndicator(string message = "Waiting...")
        {
            if (_progressIndicator == null)
            {
                _progressIndicator = new ProgressIndicator { IsIndeterminate = true };
                
                Color foregroundColor = ((SolidColorBrush) Application.Current.Resources["SpottedMainColorBrush"]).Color;
                SystemTray.SetForegroundColor((SpottedPageBase)RootFrame.Content, foregroundColor);

                Color backgroundColor = ((SolidColorBrush) Application.Current.Resources["SpottedBackgroundColorBrush"]).Color;
                SystemTray.SetBackgroundColor((SpottedPageBase)RootFrame.Content, backgroundColor);

                SystemTray.SetProgressIndicator((SpottedPageBase)RootFrame.Content, _progressIndicator);
            }

            _progressIndicator.IsVisible = true;
            _progressIndicator.Text = message;
        }

        /// <summary>
        /// Hide the Progress Indicator associated with the SystemTray
        /// </summary>
        public void HideProgressIndicator()
        {
            if (_progressIndicator != null)
                _progressIndicator.IsVisible = false;
        }

        private IList<SpotIntention> _spotIntentions;

        /// <summary>
        /// Get the standard list of Spot Intentions
        /// </summary>
        /// <returns></returns>
        // todo: reconsider how this is implemented
        public IList<SpotIntention> GetSpotIntentions()
        {
            return _spotIntentions ?? (_spotIntentions = new List<SpotIntention>
                                                                 {
                                                                     new SpotIntention
                                                                         {Id = 1, Display = "visit this place"},
                                                                     new SpotIntention
                                                                         {Id = 2, Display = "remember this place"},
                                                                     new SpotIntention
                                                                         {Id = 3, Display = "forget this place"}
                                                                 });
        }

        #endregion
    }
}
